{% extends 'AdminBundle::layout.html.twig' %}


{% block title %}banner管理{% endblock %}

    {% block css %}
        <link type="text/css" rel="stylesheet" href="{{ asset('assets/css/bootstrap-datetimepicker.min.css') }}">
    {% endblock %}


    {% block top %}
        {#{{ dump() }}#}
        {{ parent() }}
    {% endblock %}



    {% block left_body_top %}
        {{ parent() }}
    {% endblock %}

    {% block left_body %}
        {{ parent() }}
    {% endblock %}

    {% block right_body %}
    <div class="page-header">
        <div class="page-right-top">
            <div class="right-top">
                <span class="right-title">系统设置</span>
            </div>
            <div class="top-nav top-nav-active">Banner图管理</div>
        </div>

        <div class="main-content">
            <div class="mes-content">
                <div class="main-mes-top">
                    <div class="fl">
                        <a class="release-btn fl" style="width:140px;"  href="{{ path('setting_edit_banner',{id:'0'}) }}">
                            <div class="re-width" style="width: 114px;">
                                <span class="me-icon fl"></span>
                                <span class="re-text fl">添加新Banner</span>
                            </div>
                        </a>
                    </div>
                    <div class="clearfix"></div>
                </div>

                <div class="main-mes-content">
                    <div class="al-released">Banner图列表</div>

                    <table class="table">
                        <thead>
                        <tr style="background-color: #f3f9fd;">
                            <th class="center-th">序号</th>
                            <th class="center-th">Banner图片</th>
                            <th class="center-th">Banner图分类</th>
                            <th class="center-th">Banner图名称</th>
                            <th class="center-th">Banner超链接</th>
                            <th class="center-th">操作</th>
                        </tr>
                        </thead>
                        <tbody>



                        </tbody>
                    </table>

                    <div class="page-box">
                        <ul class="pagination">
                            {#<li><a href="#">&laquo;</a></li>#}
                            {#<li><a href="#" class="mes-page-check">1</a></li>#}
                            {#<li><a href="#">2</a></li>#}
                            {#<li><a href="#">3</a></li>#}
                            {#<li><a href="#">4</a></li>#}
                            {#<li><a href="#">5</a></li>#}
                            {#<li><a href="#">&raquo;</a></li>#}
                        </ul>
                    </div>
                </div>
            </div>
        </div>
    </div>

    {% endblock %}

{% block box %}
{% endblock %}


{% block javascript %}
<script src="{{ asset('assets/js/bootstrap-datetimepicker.min.js') }}" type="text/javascript"></script>
<script src="{{ asset('assets/js/bootstrap-datetimepicker.zh-CN.js') }}" type="text/javascript"></script>
    {{ parent() }}
<script type="text/javascript">
//    $(function () {
        SidebarHighlighting('8');

        SonSidebar('8', '5');
        // 删除
        $('body').on('click','.tab-disable', function() {
            var id = $(this).data("id");

            if(confirm('您确定要删除吗？')) {

                $.post("{{ path('api_admin_setting_delete_banner') }}",{id:id},function(data){
                    console.log(data);
                    if(data.errorCode == 0){
                        popStatus(1, data.message, 1,'', true);
                        $("table tbody").empty();
                        addSearchAction(1);

                    } else {
                        popStatus(2, data.message, 1,'', true);
                    }
                })


            }
        });

        // 获取banner列表
        var page_times = 0;
        function getList(page){
            page_times++;

            var param = {role:2,page:page};
            $.post("{{ path('api_admin_setting_get_banner_list') }}",param,function(data){
                $("table tbody").empty();
                console.log(data);

                var list_all_count = data.data.search_all_count;
                var allpage = data.data.all_page;

                // 分页样式
                if(page_times == 1 && allpage > 0){
                    pageAction(list_all_count,allpage);
                }


                var item = data.data.banner;
                for(var i in item){
                    var html = '';
                    var key = parseInt(i)+1;

                    var list_order_num = parseInt((parseInt(page)-1)*10+key);

                    var info_url = "{{ path('setting_edit_banner',{id:'745394769823'}) }}".replace("745394769823",item[i].id);

                    if(item[i].is_company == 0){
                        var iscompany = "管理员端";
                    } else {
                        var iscompany = "用户端";
                    }

                    var img_src = "{{ asset('') }}" + item[i].image_path;

                    html += '<tr>';
                    html += '<td class="center-th">'+ list_order_num +'</td>';
                    html += '<td class="center-th">';

                    if(item[i].image_path == ""){

                        html += '<img src="img/icon/banner-default.png" width="200" height="86" alt="">';

                    } else {

                        html += '<img src="'+ img_src +'" width="200" height="86" alt="">';
                    }

                    html += '</td>';
                    html += '<td class="center-th">'+ iscompany +'</td>';
                    html += '<td class="center-th">'+ item[i].name +'</td>';
                    html += '<td class="center-th">'+ item[i].url +'</td>';
                    html += '<td class="center-th">';
                    html += '<a class="table-opera tab-edit" href="'+ info_url +'">编辑</a>';
                    html += '<span class="table-opera tab-disable" data-id="'+ item[i].id +'">| 删除</span>';
                    html += '</td>';
                    html += '</tr>';

                    $("table tbody").append(html);
                }

            })
        }

        addSearchAction(1);


        function addSearchAction(page){
            getList(page);
        }
//    })
</script>
{% endblock %}